package com.example.role.service.serviceimpl;

import com.example.role.pojo.Office;
import com.example.role.service.OfficeEsService;
import com.example.role.service.OfficeService;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.util.UUID;

@Service
public class OfficeServiceImpl implements OfficeService {

    @Autowired
    OfficeEsService officeEsService;

    @Autowired
    OfficeImpl officeimpl;

    @Autowired
    RabbitTemplate rabbitTemplate;
//添加
    @Override
    public boolean addOffice(Office office) {
        //给订单添加uuid主键
        office.setOfficeId(UUID.randomUUID().toString()
                .replaceAll("-",""));

        //先写入到mysql 成功以后 给mq发送消息
        int i = officeimpl.addOffice(office);
        if(i==1){
            //如果添加成功 我就给mq发送一条消息 “订单添加消息”
            // 消息格式 "主键-操作类型" 比如："123123-insert"
            rabbitTemplate.convertAndSend("es.mysql.copy.data.temp"
                    ,office.getOfficeId()+"-insert");
        }

        return i==1;
    }
//搜索
    @Override
    public Page<Office> searchOffice(Office office) {
        return null;
    }
//删除
    @Override
    public boolean deleteOfficeById(String id) {
        return false;
    }
//修改
    @Override
    public boolean updateOffice(Office office) {
        return false;
    }
}
